<?php


namespace App\Models;


class PayOrder extends BaseModel
{
    protected $table = 'pay_order';
    protected $fillable = [
        'user_id',
        'account_id',
        'title',
        'order_no',
        'pay_type',
        'amount',
        'notify_data',
        'status',
    ];


    public static function getJSAPIPaySign($app_id, $prepayId, $key)
    {
        $params = [
            'appId' => $app_id,
            'nonceStr' => uniqid(),
            'timeStamp' => time(),
            'package' => 'prepay_id=' . $prepayId,
            "signType" => 'MD5',
        ];
        $params['paySign'] = self::generate_sign($params, $key);
        return $params;
    }

    public static function generate_sign(array $attributes, $key, $encryptMethod = 'md5')
    {
        ksort($attributes);
        $attributes['key'] = $key;
        return strtoupper(call_user_func_array($encryptMethod, [urldecode(http_build_query($attributes))]));
    }

}
